package com.hdax.dm.order.rest.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hdax.dm.api.OrderControllerApi;
import com.hdax.dm.entity.order.Order;
import com.hdax.dm.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderRestService implements OrderControllerApi {

    @Autowired
    private OrderService orderService;

    @Override
    public Order detail(String orderNo) {
        Order order = orderService.getOrder(orderNo);
        return order;
    }

    @Override
    public Boolean addTradeNo(String orderNo, String tradeNo) {
        return orderService.updateOrder(orderNo, tradeNo);
    }

    @Override
    public Long getCount(Long userId, Long itemId) {
        QueryWrapper<Order> queryWrapper = new QueryWrapper<Order>();
        queryWrapper.eq("userId",userId);
        queryWrapper.eq("itemId",itemId);
        return orderService.count(queryWrapper);
    }

    @Override
    public Order selectOne(String orderNo) {
        return orderService.selectOne(orderNo);
    }

    @Override
    public boolean updateTwo(String orderNo) {
        return orderService.updateOrderTwo(orderNo);
    }
}
